#include "lcd.h"
#include "lcd_3.5.h"
#include "lcd_controller.h"

#define LCD_NUM 10

static p_lcd_params p_array_lcd[LCD_NUM];
static p_lcd_params g_p_lcd_selected;

int register_lcd(p_lcd_params plcd) {
    int i;
    for (i = 0; i < LCD_NUM; i++) {
        if (!p_array_lcd[i]) {
            p_array_lcd[i] = plcd;
            return i;
        }
    }
    return -1;
}

int select_lcd(char *name) {
    int i;
    for (i = 0; i < LCD_NUM; i++) {
        if (p_array_lcd[i] && !strcmp(p_array_lcd[i]->name, name)) {
            g_p_lcd_selected = p_array_lcd[i];
            printf("choose lcd %s\r\n", p_array_lcd[i]->name);
            return i;
        }
    }
    return -1;
}

void get_lcd_params(uint32 *fb_base, int *xres, int *yres, int *bpp) {
    *fb_base = g_p_lcd_selected->fb_base;
    *xres = g_p_lcd_selected->xres;
    *yres = g_p_lcd_selected->yres;
    *bpp = g_p_lcd_selected->bpp;
}

void lcd_enable(void) { lcd_controller_enable(); }

void lcd_disable(void) { lcd_controller_disable(); }

int lcd_init(void) {
    lcd_3_5_add();

    lcd_contoller_add();

    select_lcd("lcd_3.5");

    select_lcd_controller("s3c2440");

    lcd_controller_init(g_p_lcd_selected);

    return 0;
}
